﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head><link rel="stylesheet" href="${ctx}/common/common.css">
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    
</head>
<body>
<!--主体内容层-->
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 layui-col-space15 layui-form">
            <form>
                <!--输入框内容盒子-->
                <div class="layui-col-md12">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">生产企业</label>
                        <div class="layui-input-block">
                            <input type="text" name="productionName" id="productionName"   placeholder="请输入生产企业名称" class="layui-input" style="float:left;width:70%">
                       			                    <div  class="layui-btn-group paramBtn" style="margin-left: 5%; margin-top: 3px;">
                        <button  id="companyButton"  type="button"   class="layui-btn layui-btn-sm layui-btn-danger">
                            查询
                        </button>
                        <button   type="reset" id="resetCompany"  class="layui-btn layui-btn-sm layui-btn-danger">
                            重置
                        </button>
                    </div>
                        </div>
                        
                    </div>   <!--输入框-->
                </div>
                <!--通用按钮盒子-->
                <div class="layui-col-md12" >

                </div>
                <!--通用按钮盒子-->
            </form>
            <table class="layui-table demo"  lay-data="{ url:'${ctx}/productionDetection/queryEnterpriseAllPage?companyIds=${companyIds}', page:false ,groups:5,id:'demo'}" lay-filter="demo">
                <thead>
                <tr >
                    <th lay-data="{checkbox:true}" class="checkboxTh"></th>
                    <th lay-data="{field:'name',sort:true,event:'check'}">企业名称</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-sm" lay-event="detail">领料记录</a>
    <a class="layui-btn layui-btn-sm" lay-event="edit">工艺流程</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">检验报告</a>
</script>

</body>
<script>
    var $;
    var companyIds='';
    var companyNames='';
    var oldCompanyIds;
    layui.use('table', function () {
        $=layui.$;
        var loading = layer.msg("数据加载中...");
        var table = layui.table;
        table.render({
            elem: '#demo',
            done: function () {
                layer.close(loading);
                $("#allCheck").remove();
                $("#productionCompanyId").val("");
                $("#companyName").html("");
            }
        })


        table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'check'){ //点击企业名称
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                $("#productionCompanyId",parent.document).val(data.id);
                $("#companyName",parent.document).html(data.name);
            }
        });

        table.on('checkbox(demo)', function(obj){
            console.log(obj.checked); //当前是否选中状态
            console.log(obj.data); //选中行的相关数据
            console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
            //var index = parent.layer.getFrameIndex(window.name);
            //parent.layer.close(index);
            /* if(companyIds.length<=0){
                companyIds=+obj.data.id
                companyNames=obj.data.name
            }else{
                companyIds=companyIds+","+obj.data.id
                companyNames=companyNames+","+obj.data.name
            } */
            var checkStatus = table.checkStatus('demo')
            var data = checkStatus.data;
            for (var i in data){
                if(i == 0){
                	companyIds=+data[i].id
                    companyNames=data[i].name
                }else{
                	companyIds=companyIds+","+data[i].id
                    companyNames=companyNames+","+data[i].name
                }
            }
            $("#productionCompanyId",parent.document).val(companyIds);
            $("#companyName",parent.document).html(companyNames);
        });


        /**
         * 条件查询中的查询按钮
         * */
        $("#resetCompany").on("click",function(){
            //这里以搜索为例
            table.reload('demo',{
                where: { //设定异步数据接口的额外参数，任意设
                    productionName: ''
                }
                ,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        })

        $("#companyButton").on("click",function(){
            table.reload('demo',{
                where: { //设定异步数据接口的额外参数，任意设
                    productionName: $("#productionName").val()

                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });

        })

    });

</script>
</html>



